<template>
  <div class="components-container">
    <!--礼厅登记-->
    <!-- 存入 -->
    <sweet-modal ref="dj" class="dialog">
      <h3>{{title}}</h3>
      <div style="width:700px; margin:30px 50px">
        <div class="layui-form-item">
          <label class="layui-form-label">业务编号</label>
          <div class="layui-input-inline">
            <el-input v-model="deaddata.deadseachno" placeholder="请选取逝者">
            </el-input>
          </div>
          <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadName" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">车号</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.CARLIC" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">驾驶员</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.STANAME" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.CDHADDRESS" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkMan" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkTel" readonly></el-input>
            </div>
          </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">存入时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="ichdataExtend.saveDates" type="datetime" class="longtext" placeholder="选择日期时间"> </el-date-picker>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">礼厅编号</label>
            <div class="layui-input-inline">
              <el-select v-model="mehData.MEHMEMIDS" placeholder="请选择追悼厅" style="width:100%">
                <el-option v-for="item in memNames" :key="item.value" :label="item.label" :value="item.value" :disabled="readonlymehmemid">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="showjbr">
         <div class="layui-inline" >
              <label class="layui-form-label">礼厅经办人</label>
              <div class="layui-input-inline">
                <el-select v-model="mehData.MEHCHKUSR" placeholder="请选择经办人" style="width:100%">
                  <el-option v-for="item in memjbr" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input type="textarea" v-model="mehData.MEHREMARKS" style="width:500px;"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item btnCenter">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitAdd">提交</el-button>
      </div>
    </sweet-modal>
    <!-- 编辑 -->
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="1000">
      <h3>{{title}} </h3>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>死者信息</legend>
        <div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">业务编号</label>
              <div class="layui-input-inline">
                <el-input v-model="mehData.REGNO" placeholder="请输入业务编号" :disabled="isDisabled" @keyup.enter.native="getRegInfo">
                  <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
                </el-input>
              </div>
              <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">逝者姓名</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGNAME" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">性别</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGSEXDESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">年龄</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGAGE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">详细住址</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">到馆时间</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGDATE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">接尸地址</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGADDRESS"></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">死亡日期</label>
              <div class="layui-input-inline">
                <el-input v-model="this.regList.REGDEATHDATE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">死亡原因</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGCAUSADESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">家属姓名</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">联系电话</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
              </div>
            </div>
          </div>
        </div>
      </fieldset>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>悼念厅信息</legend>
        <div>
          <div class="layui-form-item">
            <div class="layui-inline"  v-if="!showsecond">
              <label class="layui-form-label">名称</label>
              <div class="layui-input-inline">
                <el-select  v-model="mehData.MEHMEMIDS" placeholder="请选择追悼厅" style="width:100%" >
                  <el-option v-for="item in memNames" :key="item.value" :label="item.label" :value="item.value" :disabled="readonlymehmemid">
                  </el-option>
                </el-select>
              </div>
            </div>
            <div class="layui-inline"  v-if="showsecond">
              <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                <el-cascader :options="memNames" v-model="MehselectArea" filterable></el-cascader>
               </div>
            </div>
            <div class="layui-inline" v-if="showjbr">
              <label class="layui-form-label">礼厅经办人</label>
              <div class="layui-input-inline">
                <el-select v-model="mehData.MEHCHKUSR" placeholder="请选择经办人" style="width:100%">
                  <el-option v-for="item in memjbr" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">开始时间</label>
              <div class="layui-input-inline">
                <el-date-picker v-date v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
              </div>
            </div>
            <div class="layui-inline" v-if="isBEG">
              <label class="layui-form-label">结束时间</label>
              <div class="layui-input-inline">
                <el-date-picker v-date v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
                <el-input type="textarea" v-model="mehData.MEHREMARKS" style="width:768px;"></el-input>
              </div>
            </div>
          </div>
        </div>
      </fieldset>
      <fieldset class="layui-elem-field layui-field-title" v-if="IsMournPushCharge && this.title != '追悼厅使用新增' && this.title != '追悼厅结束使用'">
        <legend>费用项目</legend>
        <div>
          <el-button style="margin-left: 19px;margin-bottom:10px;" type="success" @click="chargeChoose">选择收费项目</el-button>
        </div>
        <table class="layui-table" style="border-spacing: 0;width:96%;margin:auto !important">
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>费用名称</th>
              <th>单位</th>
              <th>数量</th>
              <th>单价</th>
              <th>金额</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(chl,index) in chlList" :key="index">
              <td>
                <el-select @change="chaSelect(index)" ref="select" v-model="chl.CHLCHAID" clearable @keydown.enter.native="enterEvent(index,0)" filterable :filter-method="chaFilter" @visible-change="reset()">
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLAUNIT" readonly>
                  <!-- <template slot="append">元</template> -->
                </el-input>
                <!-- {{chl.DPTNAME}} -->
              </td>
              <td>
                <el-input @input="changemoney(index,$event)" @keydown.enter.native="enterEvent(index,2)" v-model="chl.CHLNUM">
                  <!-- <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template> -->
                </el-input>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,3)" v-model="chl.CHLMONEY">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,3)" v-model="chl.CHLMOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>

              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>

            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="1">
                <span>合计</span>
              </td>
              <td>
              </td>
              <td></td>
              <td></td>
              <td>{{ discountTotal }}</td>
              <!-- <td></td>
                    <td></td> -->
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </fieldset>
      <div class="layui-form-item btnCenter">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </sweet-modal>
    <!-- 详情 -->
    <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="1000">
      <h3>{{title}} </h3>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>死者信息</legend>
        <div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">业务编号</label>
              <div class="layui-input-inline">
                <el-input v-model="mehData.REGNO" placeholder="请输入业务编号" readonly></el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">逝者姓名</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGNAME" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">性别</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGSEXDESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">年龄</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGAGE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">详细住址</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">到馆时间</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGDATE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">接尸地址</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGADDRESS"></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">死亡日期</label>
              <div class="layui-input-inline">
                <el-input v-model="this.regList.REGDEATHDATE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">死亡原因</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGCAUSADESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">家属姓名</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">联系电话</label>
              <div class="layui-input-inline">
                <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
              </div>
            </div>
          </div>
        </div>
      </fieldset>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>悼念厅信息</legend>
        <div>
          <div class="layui-form-item">
            <div class="layui-inline" v-if="!showsecond">
              <label class="layui-form-label">悼念厅名称</label>
              <div class="layui-input-inline">
                <el-input v-model="mehData.MEMNAME" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline"  v-if="showsecond">
              <label class="layui-form-label">悼念厅名称</label>
              <div class="layui-input-inline">
                <el-input v-model="mehData.MEMALIAS" readonly></el-input>
              </div>
            </div>
             <div class="layui-inline" v-if="showjbr">
              <label class="layui-form-label">礼厅经办人</label>
              <div class="layui-input-inline">
                <el-input v-model="mehData.MEHCHKUSR" readonly></el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">开始时间</label>
              <div class="layui-input-inline">
                <el-date-picker v-date readonly v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
              </div>
            </div>
            <div class="layui-inline" v-if="isBEG">
              <label class="layui-form-label">结束时间</label>
              <div class="layui-input-inline">
                <el-date-picker v-date readonly v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
                <el-input type="textarea" readonly v-model="mehData.MEHREMARKS" style="width:768px;"></el-input>
              </div>
            </div>
          </div>
        </div>
      </fieldset>
      <fieldset class="layui-elem-field layui-field-title" v-if="IsMournPushCharge">
        <legend>费用项目</legend>
        <table class="layui-table" style="border-spacing: 0;width:96%;margin:auto !important">
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>费用名称</th>
              <th>单位</th>
              <th>数量</th>
              <th>单价</th>
              <th>金额</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(chl,index) in chlList">
              <td>
                <el-select v-model="chl.CHLCHAID" clearable filterable :filter-method="chaFilter">
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID" disabled>
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input v-model="chl.CHLAUNIT" readonly>
                  <!-- <template slot="append">元</template> -->
                </el-input>
                <!-- {{chl.DPTNAME}} -->
              </td>
              <td>
                <el-input v-model="chl.CHLNUM" readonly>
                  <!-- <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template> -->
                </el-input>
              </td>
              <td>
                <el-input v-model="chl.CHLMONEY" readonly>
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input v-model="chl.CHLMOUNT" readonly>
                  <template slot="append">元</template>
                </el-input>
              </td>

              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="1">
                <span>合计</span>
              </td>
              <td>
              </td>
              <td></td>
              <td></td>
              <td>{{ discountTotal }}</td>
              <!-- <td></td>
                    <td></td> -->
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </fieldset>
      <div class="layui-form-item btnCenter">
        <el-button @click="cancel">取消</el-button>
      </div>
    </sweet-modal>
    <!-- 逝者选择 -->
    <sweet-modal ref="deadSelect" class="dialog">
      <h3>逝者选择</h3>
      <div class="layui-form-item">
        <label class="layui-form-label">到馆时间</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="regCheckDate" @change="getRegData" type="date" placeholder="选择日期时间">
          </el-date-picker>
        </div>
      </div>
      <div style="height:400px;max-height:400px;overflow:auto;">
        <table class="layui-table">
          <thead>
            <tr>
              <th>业务编号</th>
              <th>逝者姓名</th>
              <th>联系人</th>
              <th>死亡日期</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in regCheckList">
              <td>{{item.REGBUSNUM}}</td>
              <td>{{item.REGNAME}}</td>
              <td>{{item.REGHANDLERNAME}}</td>
              <td>{{item.REGDEATHDATE}}</td>
              <td>
                <button @click="getDead(item)" class="layui-btn layui-btn-normal">选择</button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </sweet-modal>
    <chargeChoose ref="chargeChoose" :SOURCE="'悼念厅费用'" @makeSure="makeSure"></chargeChoose>
  </div>

</template>

<style rel="stylesheet/scss" lang="scss" scoped>
.layui-input-inline button.el-button {
    outline: none;
}
</style>
<script>
import apiBase from "@/api/apiBase.js";
import sweetModal from "@/components/sweetModal";
import chargeChoose from "@/components/chargeChoose/partCharge";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { accMul, Subtr, accAdd } from "@/utils/operations.js";

const ADD = "新增";
const MODIFY = "修改";
const INFO = "详情";
const BEG = "开始使用";
const END = "结束使用";
const REG = "礼厅登记";

export default {
    name: "mourningUseMain",
    mixins: [manage],
    data() {
        return {
            showLin:false,
            showjbr:null,
            title: null,
            memNames: [],
            memjbr: [],  //经办人下拉集合
            selectData: {},
            mehData: {
                MEHMEMIDS: null,
                MEHREMARKS: null,
                MEHCHKUSR:null,
            },
            regList: [],
            useTime: null,
            staTime: null,
            endTime: null,
            id: null,
            regdatatime: null,
            readonlymehmemid: false,

            regCheckDate: null,
            regCheckList: null,
            deaddata: {
                deadseachno: null,
                deadselectno: null,
                deadid: null,
                deadName: null,
                deaddate: null,
                linkMan: null,
                linkTel: null,
                deadRemark: null
            },
            ichdataExtend: {
                ichEndDates: null,
                saveDates: null
            },
            cdhdata: {
                CARLIC: null,
                CDHADDRESS: null,
                CDHLINKMAN: null,
                CDHDRIVER: null,
                STANAME: null
            },
            QueryDriver: [],
            iceid: null,
            //收费项目
            chlList: [],
            chaList: [],
            chl: {
                CHLCHAID: "", //名称
                CHLAUNIT: null, //单位
                CHLNUM: null, //数量
                CHLMONEY: null, //单价
                CHLMOUNT: null, //金额
                CHLDISCOUNT: null,
                CHLDM: null,
                CHLHIDISCOUNT: null,
                CHLJMHIMONEY: null,
                CHLJMMONEY: null,
                CHLNAME: null,
                CHLPRICE: null
            },
            IsMournPushCharge: null,
            IsTakeRegOrPrp: null,
            IsUseMemToReg: null,
            showsecond:null,
            MehselectArea:[],
        };
    },
    methods: {
        // 选择收费项目
        chargeChoose() {
            this.$refs.chargeChoose.open("选择收费项目",this.chlList);
        },
        makeSure(val) {
            let arr = val.map(item => {
                let cha = this.getChaByID(item.CHAID);
                //初始化chl
                if (cha) {
                    let chl = {
                        CHALOGO: cha.CHALOGO,
                        CHLCHAID: item.CHAID,
                        CHLCHANAME: cha.CHANAME,
                        CHLAUNIT: cha.CHAAUNIT,
                        CHLMONEY: cha.CHAMONEY,
                        CHLNUM: 1,
                        CHLMOUNT: cha.CHAMONEY,
                        CHLREDUCTION: cha.CHAJMMONEY,
                        CHLDISCOUNT: cha.CHADISCOUNT,
                        CHLRECEIVED:
                            cha.CHAMONEY - cha.CHAJMMONEY - cha.CHADISCOUNT,
                        CHAMODIFYJMMONEY: cha.CHAMODIFYJMMONEY
                    };
                    return chl;
                }
            });
            if(this.chlList.length>0){
              if(this.chlList[this.chlList.length-1].CHLCHAID == ''){
                this.chlList.splice(this.chlList.length - 1, 1);
              }
            }
            this.chlList = this.chlList.concat(arr);
            this.insert();
        },
        open(order, id, meh) {
            this.order = order;
            this.id = id;
            this.chlList = [];
            this.getMem(); //获取悼念厅
            this.getAllCharge(); //获取收费项目
            this.GetIsMournPushCharge(); //个性化 悼念厅管理是否推送收费记录
            this.readonlymehmemid = false;
            switch (this.order) {
                case ADD:
                    this.title = "追悼厅使用新增";
                    this.dataRepeat();
                    this.$refs.dialog.open();
                    break;
                case REG:
                    this.title = "追悼厅礼厅登记";
                    this.dataRepeat();
                    this.$refs.dj.open();
                    break;
                case MODIFY:
                    this.dataRepeat();
                    this.title = "追悼厅使用修改";
                    this.dataInfo(id);
                    if(this.showLin==true){
                    this.readonlymehmemid = false;
                    }else{
                    this.readonlymehmemid = true;
                    }
                    this.$refs.dialog.open();
                    break;
                case INFO:
                    this.title = "追悼厅使用详情";
                    this.dataInfo(id);
                    this.$refs.info.open();
                    break;
                case BEG:
                    this.dataRepeat();
                    this.insert();
                    this.title = "追悼厅开始使用";
                    if (meh) {
                        this.mehData.MEHMEMIDS = id;
                        this.readonlymehmemid = true;
                    }
                    this.$refs.dialog.open();
                    break;
                case END:
                    this.title = "追悼厅结束使用";
                    this.dataInfo(id);
                    this.readonlymehmemid = true;
                    this.$refs.dialog.open();
                    break;
                default:
            }
        },
        //提交
        submit() {
            switch (this.order) {
                case ADD:
                    this.dataAdd();
                    break;
                case MODIFY:
                    this.dataModify(this.id);
                    break;
                case BEG:
                    this.startUse();
                    break;
                case END:
                    this.endUse(this.id);
                    break;
                default:
            }
        },
        //获取悼念厅
        getMem() {
             //获取经办人下拉
            apiBase.DoService(
                {STACODNAME:'殡仪员'},
                apiBase.getApiAdress().User.QueryUsrAll,
                res => {
                    let mehTypeData = res.data.content,
                        legendsMehData = mehTypeData.map(item => ({
                            label: item.USRNAME,
                            value: item.USRNAME
                        }));
                    this.memjbr = legendsMehData;
                }
            );
            if(this.showsecond==true){
              return new Promise((resolve,reject)=>{
              apiBase.DoService(
                  {},
                  apiBase.getApiAdress().MemorialUse.QueryMemSecond,
                  res => {
                  let mehTypeData = res.data.content;
                      this.memNames = mehTypeData.map(item => ({
                          label: item.CODALIAS,
                          value: item.CODNAME,
                            children: item.list_MEM.map(itemCau => ({
                            label: itemCau.MEMNAME,
                            value: itemCau.MEMID
                          }))
                      }));
                    resolve() 
                });
            })
            }else{
              apiBase.DoService(
                  {},
                  apiBase.getApiAdress().MemorialUse.QueryMemorial,
                  res => {
                      let mehTypeData = res.data.content,
                          legendsMehData = mehTypeData.map(item => ({
                              label: item.MEMNAME,
                              value: item.MEMID
                          }));
                      this.memNames = legendsMehData;
                  }
              );
            }
     
        },
        //个性化  悼念厅管理是否推送收费记录
        GetIsMournPushCharge() {
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsMournPushCharge,
                res => {
                    this.IsMournPushCharge = res.data.content;
                }
            );
        },
        //根据正式业务编号获取info
        getRegInfo() {
            if (this.mehData.REGNO === null) {
                this.$message({
                    message: "没有业务编号",
                    type: "warning"
                });
            } else {
                let data = {
                    REGNO: this.mehData.REGNO
                };
                if(this.IsTakeRegOrPrp){
                  apiBase.DoService(
                      data,
                      apiBase.getApiAdress().Registration.GetRegOrPrpByNo,
                      res => {
                          this.regList = res.data.content;
                      }
                  );
                }else{
                  apiBase.DoService(
                      data,
                      apiBase.getApiAdress().Registration.GetRegistrationByNo,
                      res => {
                          this.regList = res.data.content;
                      }
                  );
                }
            }
        },
        //gy
        SeachDead(ev) {
            if (ev.keyCode === 13) {
                this.IsEnter = true;
                let data = {
                    // ICHICEID: this.icedata.iceid,
                    ICHREGBUSNUM: this.deaddata.deadseachno
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().IceUse.GetRegistrationAndUseByNo,
                    res => {
                        if (res.data.content.REG) {
                            this.deaddata.deadid = res.data.content.REG.REGID;
                            this.deaddata.deadName =
                                res.data.content.REG.REGNAME;
                            this.deaddata.deaddate =
                                res.data.content.REG.REGDEATHDATE;
                            this.deaddata.linkMan =
                                res.data.content.REG.REGHANDLERNAME;
                            this.deaddata.linkTel =
                                res.data.content.REG.REGHANDLERLINK;
                        }
                    }
                );
            } else {
                if (this.IsEnter === true) {
                    this.deaddata.deadseachno = "";
                    this.IsEnter = false;
                }
            }
        },
        submitAdd() {
            //确定存入
            if(this.showsecond){
              if(this.MehselectArea.length!=0){
              this.mehData.MEHMEMIDS=this.MehselectArea[this.MehselectArea.length-1]
              }
            }
            let data = {
                //请求体
                MEHMEMID: this.mehData.MEHMEMIDS, //冰柜id
                MEHREGBUSNUM: this.deaddata.deadseachno, //逝者编号
                MEHBEGDATE: formatDate(
                    this.ichdataExtend.saveDates,
                    "yyyyMMdd"
                ), //存入时间
                MEHBEGTIME: formatDate(this.ichdataExtend.saveDates, "hhmmss"), //存入日期
                MEHREMARKS: this.mehData.MEHREMARKS,
                MEHCHKUSR: this.mehData.MEHCHKUSR
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().MemorialUse.PrpStartUse,
                res => {
                    // this.cancel();
                    this.refreshData();
                    this.$refs.dj.close();
                    this.$message.success("存入成功");
                }
            );
        },
        //打开逝者选取
        openRegCheck() {
            this.regCheckDate = new Date();
            this.getRegData();
            this.$refs.deadSelect.open();
            // this.regCheckVisible = true;
        },
        //获取火化登记数据
        getRegData() {
            let data = {
                Data: {
                    RegdateEquals: formatDate(this.regCheckDate, "yyyyMMdd")
                }
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Registration.QueryRegistration,
                res => {
                    this.regCheckList = res.data.content.OutData;
                    // this.cdhdata.CARLIC = res.data.content.CARLIC;
                    // this.cdhdata.CDHADDRESS = res.data.content.CARLIC;
                    // this.cdhdata.CDHLINKMAN = res.data.content.CARLIC;
                }
            );
        },
        //选择
        getDead(item) {
            this.mehData.REGNO = item.REGBUSNUM;
            this.getRegInfo()
            this.$refs.deadSelect.close();
        },
        //新增（补录）
        dataAdd() {
            //二级下拉
            if(this.showsecond){
              if(this.MehselectArea.length!=0){
              this.mehData.MEHMEMIDS=this.MehselectArea[this.MehselectArea.length-1]
              }
            }
            apiBase.DoService(
                {
                    MEHMEMID: this.mehData.MEHMEMIDS,
                    MEHREGID: this.regList.REGID,
                    MEHCHKUSR: this.regList.MEHCHKUSR,
                    MEHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                    MEHBEGTIME: formatDate(this.staTime, "hhmmss"),
                    MEHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                    MEHENDTIME: formatDate(this.endTime, "hhmmss")
                },
                apiBase.getApiAdress().MemorialUse.Memate,
                res => {
                    this.$refs.dialog.close();
                    this.$message({
                        type: "success",
                        message: "新增成功!"
                    });
                    this.refreshData();
                },
                res => {
                    this.$message.error(res.data.msg);
                }
            );
        },
        //悼念厅开始使用
        startUse() {
            let Data = {};
            let chlList = JSON.parse(JSON.stringify(this.chlList));
            if (chlList.length > 0) {
                Data = chlList;
                if(chlList[chlList.length-1].CHLCHAID == ''){
                  chlList.splice(chlList.length - 1, 1);
                }
            }
            //二级下拉
            if(this.showsecond){
              if(this.MehselectArea.length!=0){
              this.mehData.MEHMEMIDS=this.MehselectArea[this.MehselectArea.length-1]
              }
            }
            if(this.IsUseMemToReg){
              apiBase.DoService(
                {
                    MEHMEMID: this.mehData.MEHMEMIDS,
                    MEHREGBUSNUM: this.mehData.REGNO,
                    MEHREMARKS: this.mehData.MEHREMARKS,
                    MEHCHKUSR: this.mehData.MEHCHKUSR,
                    MEHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                    MEHBEGTIME: formatDate(this.staTime, "hhmmss"),
                    List_Chl: Data
                },
                apiBase.getApiAdress().MemorialUse.PrpStartUse,
                res => {
                    this.$message({
                        type: "success",
                        message: "新增成功!"
                    });
                    this.$refs.dialog.close();
                    this.refreshData();
                }
              );
            }else{
              apiBase.DoService(
                {
                    MEHMEMID: this.mehData.MEHMEMIDS,
                    MEHREGID: this.regList.REGID,
                    MEHREMARKS: this.mehData.MEHREMARKS,
                    MEHCHKUSR: this.mehData.MEHCHKUSR,
                    MEHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                    MEHBEGTIME: formatDate(this.staTime, "hhmmss"),
                    List_Chl: Data
                },
                apiBase.getApiAdress().MemorialUse.MemorialStartUse,
                res => {
                    this.$message({
                        type: "success",
                        message: "新增成功!"
                    });
                    this.$refs.dialog.close();
                    this.refreshData();
                }
              );
            }
        },
        //悼念厅结束使用
        endUse(id) {
            let Data = JSON.parse(JSON.stringify(this.mehData));
             if(this.showsecond){
              if(this.MehselectArea.length!=0){
              this.mehData.MEHMEMIDS=this.MehselectArea[this.MehselectArea.length-1]
              }
            }
            apiBase.DoService(
                {
                    MEHMEMID: this.mehData.MEHMEMIDS,
                    MEHID: id,
                    MEHREGID: this.regList.REGID,
                    MEHREMARKS: this.mehData.MEHREMARKS,
                    MEHCHKUSR: this.mehData.MEHCHKUSR,
                    MEHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                    MEHENDTIME: formatDate(this.endTime, "hhmmss")
                },
                apiBase.getApiAdress().MemorialUse.MemorialEndUse,
                res => {
                    this.$message({
                        type: "success",
                        message: "结束使用成功!"
                    });
                    this.$refs.dialog.close();
                    this.refreshData();
                },
                res => {
                    this.$message.error(res.data.msg);
                }
            );
        },
        //详情
        dataInfo(id) {
            var data = {
                MEHID: id
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().MemorialUse.Detail,
                res => {
                    let mehData = res.data.content;
                    if(res.data.content.Chl){
                     this.chlList = mehData.Chl;
                    } 
                    this.mehData.REGNO = mehData.REGBUSNUM;

                      if(this.showsecond){
                        this.mehData.MEMALIAS = mehData.MEMALIAS;
                        this.MehselectArea=[mehData.MEMCODNAME,mehData.MEHMEMID]
                      } else{
                      this.mehData.MEMNAME = mehData.MEMNAME;
                      this.mehData.MEHMEMIDS = mehData.MEHMEMID;
                      }
                      this.mehData.MEHREMARKS = mehData.MEHREMARKS;
                    if(mehData.MEHCHKUSR){
                    this.mehData.MEHCHKUSR = mehData.MEHCHKUSR; //礼厅经办人
                    }
                    this.regList = mehData;
                    this.staTime = timeStringToDate(
                        mehData.MEHBEGTIME,
                        mehData.MEHBEGDATE
                    );
                    this.endTime = timeStringToDate(
                        mehData.MEHENDTIME,
                        mehData.MEHENDDATE
                    );
                }
            );
        },
        //修改
        dataModify(id) {
            let Data = {};
            let chlList = JSON.parse(JSON.stringify(this.chlList));
            if (chlList.length > 0) {
                Data = chlList;
                if(chlList[chlList.length-1].CHLCHAID == ''){
                  chlList.splice(chlList.length - 1, 1);
                }
            }
            var data = {
                MEHID: id,
                MEHREMARKS: this.mehData.MEHREMARKS,
                MEHCHKUSR: this.mehData.MEHCHKUSR,
                MEHMEMID: this.showsecond?this.MehselectArea.pop():this.mehData.MEHMEMIDS,
                MEHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                MEHBEGTIME: formatDate(this.staTime, "hhmmss"),
                MEHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                MEHENDTIME: formatDate(this.endTime, "hhmmss"),
                MEHREGID: this.regList.REGID,
                List_Chl: Data
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().MemorialUse.Modify,
                res => {
                    this.$message({
                        message: "修改成功！",
                        type: "success"
                    });
                    this.$refs.dialog.close();
                    this.refreshData();
                },
                res => {
                    this.$message.error(res.data.msg);
                }
            );
        },
        //新增行
        insert() {
            for (let index in this.chlList) {
                let chl = this.chlList[index];
                if (chl.CHLCHAID.length === 0) {
                    this.$message({
                        type: "error",
                        message: `第${parseInt(index) + 1}行收费项目不能为空!`
                    });
                    return false;
                }
            }
            this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
            return true;
        },
        reset() {
            this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        },
        //收费项目
        getAllCharge() {
            let data = {
                SOURCE: "悼念厅费用"
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Checkout.GetChargeBySource,
                res => {
                    this.allCharge = res.data.content;
                    this.chaList = JSON.parse(JSON.stringify(this.allCharge));
                }
            );
        },
        chaSelect(index) {
            // CHLMOUNT
            let chl = this.chlList[index];
            let cha = this.getChaByID(chl.CHLCHAID);
            if (cha) {
                chl.CHLAUNIT = cha.CHAAUNIT;
                chl.CHLMONEY = cha.CHAMONEY;

                chl.CHLCHAID = cha.CHAID;
                chl.CHLDISCOUNT = cha.CHADISCOUNT;
                chl.CHLDM = cha.CHADM;
                chl.CHLHIDISCOUNT = cha.CHAHIDISCOUNT;
                chl.CHLJMHIMONEY = cha.CHAJMHIMONEY;
                chl.CHLJMMONEY = cha.CHAJMMONEY;
                chl.CHLNAME = cha.CHANAME;
                chl.CHLPRICE = cha.CHAPRICE;
                chl.CHLNUM = 1;
                chl.CHLMOUNT = cha.CHAMONEY;
            }
        },
        //ID获取收费项目
        getChaByID(chaId) {
            for (var i in this.allCharge) {
                var cha = this.allCharge[i];
                if (cha.CHAID === chaId) {
                    return cha;
                }
            }
        },
        //计算金额
        changemoney(index, num) {
            let chl = this.chlList[index];
            chl.CHLMOUNT = Number(num) * Number(chl.CHLMONEY);
        },
        check(index) {
            let chl = this.chlList[index];
            chl.CHLMOUNT = Number(chl.CHLMONEY) * Number(chl.CHLNUM);
        },
        //回车事件
        enterEvent(rowNum, colNum) {
            //获取所有行
            let rows = this.$refs.inputs.getElementsByClassName("allRow");
            //获取当前行
            let currow = rows[rowNum];
            // 获取当前行所有列
            let inputs = currow.getElementsByTagName("input");
            //强制隐藏下拉框
            if (colNum === 0) {
                let chl = this.chlList[rowNum];
                if (chl.CHLCHAID.length === 0) {
                    this.$message({
                        type: "error",
                        message: `第${parseInt(rowNum) + 1}行收费项目不能为空!`
                    });
                    return;
                }
                let select = this.$refs.select;
                select[rowNum].visible = false;
            }
            //最后一列
            if (colNum === inputs.length - 1) {
                //最后一行
                if (rowNum === this.chlList.length - 1) {
                    //插入空行
                    if (!this.insert()) {
                        return;
                    }
                }
                //换行
                this.$nextTick(function() {
                    this.enterEvent(rowNum + 1, -1);
                });
            } else {
                //获取下一个焦点
                this.$nextTick(function() {
                    inputs[colNum + 1].select();
                });
            }
        },
        remove(index) {
            this.chlList.splice(index, 1);
        },
        //自定义筛选
        chaFilter(val) {
            const PinyinMatch = require("pinyin-match");
            if (val) {
                var result = [];
                this.allCharge.forEach(i => {
                    var m = PinyinMatch.match(i.CHANAME, val);
                    if (m) {
                        result.push(i);
                    }
                });
                this.chaList = result;
            } else {
                this.chaList = this.allCharge;
            }
        },
        //数据重置
        dataRepeat() {
            Object.assign(this.$data.deaddata, this.$options.data().deaddata);
            this.staTime = null;
            this.endTime = null;
            this.regList = {};
            this.cdhdata = {};
            this.ichdataExtend.saveDates = null;
            this.mehData = {
                MEHMEMIDS: null,
                MEHREMARKS: null,
                MEHCHKUSR: null,
                REGNO: null
            };
            this.MehselectArea=[];
        },
        cancel() {
            this.$refs.dialog.close();
            this.$refs.info.close();
            this.$refs.dj.close();
        },
        refreshData() {
            this.$emit("refreshData");
        },
        test() {

        }
    },
    components: {
        sweetModal,
        chargeChoose
    },
    computed: {
        isBEG() {
            if (this.order == BEG) return false;
            else return true;
        },
        isEND() {
            if (this.order == END) return false;
            else return true;
        },
        discountTotal() {
            let total = 0;
            for (let chl of this.chlList) {
                total = accAdd(total, chl.CHLMOUNT);
            }
            return total;
        }
    },
    mounted() {
    },
    created(){
     //悼念厅下拉是否使用二级下拉(上虞))
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsUseMemSecond,
          res => {
              this.showsecond = res.data.content;
          }
      );
      // 礼厅开始使用是否取预约火化信息(嵊州)
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsTakeRegOrPrp,
          res => {
              this.IsTakeRegOrPrp = res.data.content;
          }
      );
      // 礼厅开始使用是否做到馆登记(嵊州)
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsUseMemToReg,
          res => {
              this.IsUseMemToReg = res.data.content;
          }
      );
      // 礼厅使用是否显示经办人(上虞))
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsShowRitualPersonCharge,
          res => {
              this.showjbr = res.data.content;
          }
      );
      //礼厅修改是否可以修改礼厅(上虞))
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsUpdateMem,
          res => {
              this.showLin = res.data.content;
          }
      );

    },
};
</script>
